package com.example.bys.zyfypt_103fbw.activity;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.RelativeLayout;

import com.example.bys.zyfypt_103fbw.R;

public class MainActivity extends AppCompatActivity{

    private ImageButton imageButton;
    //private TextView tvLogin,tvRegister,tvLoginbtn,tvRegisterbtn;
    private RelativeLayout rl_explain,rl_light_screen;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        tvLogin=(TextView)findViewById(R.id.textView_loginText);
//        tvRegister=(TextView)findViewById(R.id.textView_registerText);

        toolBarInit();

        imageButton=(ImageButton)findViewById(R.id.imageButton_main);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showdialog();//创建并显示对话框
            }
        });
    }

    private void showdialog() {


        AlertDialog menuDialog = new AlertDialog.Builder(MainActivity.this, R.style.MenuDialog).create();
        menuDialog.show();
        Window window = menuDialog.getWindow();
        window.setContentView(R.layout.maindialogmenulayout);
        window.setGravity(Gravity.CENTER); //设置对话框在界面底部显示
        WindowManager.LayoutParams params = window.getAttributes();
        window.setAttributes(params);//此句代码一定要放在show()后面，否则不起作用
        menuDialog.setCanceledOnTouchOutside(true);
        rl_explain = (RelativeLayout) window.findViewById(R.id.rl_explain);
        rl_light_screen = (RelativeLayout) window.findViewById(R.id.rl_light_screen);
        rl_explain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,LoginActivity.class);
                startActivity(intent);
            }
        });
        rl_light_screen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,RegisterActivity.class);
                startActivity(intent);
            }
        });
    }

    private void toolBarInit() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle("选择界面");
    }
}
